import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import { setTitle } from '../../src/hammer/navigation.mts';

describe('navigation', () => {
  // 保存原始的document.title
  let originalTitle: string;

  beforeEach(() => {
    // 保存原始标题并在每个测试前重置
    originalTitle = document.title;
  });

  afterEach(() => {
    // 每个测试后恢复原始标题
    document.title = originalTitle;
  });

  describe('setTitle', () => {
    it('should set the document title', () => {
      const testTitle = 'Test Title';
      setTitle(testTitle);
      expect(document.title).toBe(testTitle);
    });

    it('should handle empty string title', () => {
      setTitle('');
      expect(document.title).toBe('');
    });

    it('should handle special characters in title', () => {
      const testTitle = 'Test Title with special chars: !@#$%^&*()';
      setTitle(testTitle);
      expect(document.title).toBe(testTitle);
    });
  });
});
